package pac1_rgr;

import process.Actor;
import queues.QueueForTransactions;
import widgets.ChooseRandom;

public class GenerCar1 extends Actor{
	

	private ChooseRandom rnd;
	
	public void setRnd(ChooseRandom rnd) {
		this.rnd = rnd;
	}

	private double finishTime;
	private Main gui;
	private Model model;
	private QueueForTransactions queueOfCars;
	
	public GenerCar1(String string, Main gui, Model model) {
		this.setNameForProtocol(string);
		rnd = gui.getChooseRandomCar1();
		queueOfCars = model.getQueueOfCars();
		finishTime = gui.getChooseDataModelTime().getDouble();
		this.gui=gui;
		this.model=model;
	}

	@Override
	protected void rule() {

		while(true){
			holdForTime(rnd.next());
			if (getDispatcher().getCurrentTime()>finishTime) return;
			queueOfCars.addLast(new Car("Avto",gui,model));
		}
		
		
	}

}
